<template>
    <div class="createSongSheet" v-if="is">
        <p>创建歌单</p>
        <div>
            <input v-model="songSheetName" placeholder="请输入歌单名称" placeholder-class="input-placeholder" />
            <span>{{ songSheetName.length }}/30</span>
        </div>
        <div>
            <button @click="cancel">取消</button>
            <button @click="CreateSongSheet">创建</button>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref, defineProps, defineEmits } from 'vue'
import { createSongSheet } from '@/api/songSheet/index'

const emit = defineEmits(['cancel', 'createSongSheets'])
defineProps({
    is: {
        type: Boolean,
        default: false
    },
})

const songSheetName = ref<string>('')//歌单名称
// 发出取消事件
function cancel() {
    emit("cancel", false)
}
// 创建歌曲表单
function CreateSongSheet() {
    // 创建歌曲表单
    createSongSheet({ name: songSheetName.value }).then(res => {
        // 发出创建歌曲表单的事件
        emit("createSongSheets", res.data.playlist)
        // 取消操作
        cancel()
    })
}
</script>

<style lang="scss" scoped>
.createSongSheet {
    width: 30vw;
    height: 20vw;
    border-radius: 10px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #2E2E2E;
    animation: identifier 0.5s ease-in-out;

    P {
        margin: 18px;
        font-size: 18px;
        color: #ccc;
    }

    >div:nth-child(2) {
        width: 90%;
        height: 4vw;
        line-height: 2.3vw;
        margin: auto;
        background: #333333;
        color: #747474;
        border-radius: 10px;
    }

    input {
        background: #333333;
        color: #747474;
        width: 80%;
        margin: 10px 0 0 10px;
        padding-left: 10px;
        border: 0;
    }

    >div:nth-child(3) {
        margin-top: 40px;
        margin-right: 15px;
        text-align: right;
    }

    button {
        width: 8vw;
        height: 3vw;
        margin-left: 20px;
        background: #202020;
        color: #fff;
        font-weight: 700;
        border: 0;
        border-radius: 4px;
        font-size: 12px;
    }
}

@keyframes identifier {
    0% {
        opacity: 0;
    }

    100% {
        opacity: 1;
    }
}
</style>